package com.project.core.utils;

import java.util.Properties;

import org.apache.log4j.BasicConfigurator;
import org.apache.log4j.Level;
import org.apache.log4j.Logger;
import org.apache.log4j.Priority;
import org.apache.log4j.PropertyConfigurator;
import org.apache.log4j.xml.DOMConfigurator;

public class Log {

	private static boolean		inited		= false;

	private static Priority[]	priority	= { Level.DEBUG, Level.INFO, Level.WARN, Level.ERROR, Level.FATAL };

	private static Logger		logger		= Logger.getLogger("log");

	protected Log() {
	}

	public static void init(Properties p) {
		if (!inited) {
			PropertyConfigurator.configure(p);
			inited = true;
		}
	}

	public static void initXml(String fileName) {
		if (!inited) {
			DOMConfigurator.configure(fileName);
			inited = true;
		}
	}

	public static void init() {
		if (!inited) {
			BasicConfigurator.configure();
			inited = true;
		}
	}

	public static void debug(Object message) {
		logger.debug(message);
	}

	public static void debug(Object message, Throwable t) {
		logger.debug(message, t);
	}

	public static void error(Object message) {
		logger.error(message);
	}

	public static void error(Throwable t) {
		logger.error(t.getMessage(), t);
	}

	public static void error(Object message, Throwable t) {
		logger.error(message, t);
	}

	public static void fatal(Object message) {
		logger.fatal(message);
	}

	public static void fatal(Throwable t) {
		logger.fatal(t.getMessage(), t);
	}

	public static void fatal(Object message, Throwable t) {
		logger.fatal(message, t);
	}

	public static void info(Object message) {
		logger.info(message);
	}

	public static void info(Object message, Throwable t) {
		logger.info(message, t);
	}

	public static void log(int level, Object message, Throwable t) {
		logger.log(priority[level], message, t);
	}

	public static void log(int level, Object message) {
		logger.log(priority[level], message);
	}

	public static void warn(Object message) {
		logger.warn(message);
	}

	public static void warn(Throwable t) {
		logger.warn(t.getMessage(), t);
	}

	public static void warn(Object message, Throwable t) {
		logger.warn(message, t);
	}

	public static boolean isDebugEnabled() {
		return logger.isDebugEnabled();
	}

	public static boolean isInfoEnabled() {
		return logger.isInfoEnabled();
	}

	public static boolean isWarnEnabled() {
		return logger.isEnabledFor(Level.WARN);
	}

	public static boolean isErrorEnabled() {
		return logger.isEnabledFor(Level.ERROR);
	}

	public static boolean isFatalEnabled() {
		return logger.isEnabledFor(Level.FATAL);
	}
}
